package com.ruoyi.merchant.util;

/**
 * @author zsl
 * app响应对象
 */
public class MyStringUtils {
    private static final String LEFT = "left";
    private static final String RIGHT = "right";
    /**
     * 指定长度字符串
     *
     * @param str 原字符串
     * @param len 字符串长度
     * @param addStr 需要补的字符
     * @param direction 方向 左右
     */
    public static String formatStr(String str , Integer len ,String addStr, String direction){
        if (len == null || str.length() >= len || isEmpty(direction)){
            return str;
        }
        if (isEmpty(addStr)){
            addStr = "0";
        }
        if (str.length() < len){
            if (direction.equals(LEFT)){
                while (str.length() < len){
                    str = addStr+str;
                }

            }else if (direction.equals(RIGHT)){
                while (str.length() < len){
                    str = str+addStr;
                }
            }
        }
        return str;
    }
    /**
     * 字符串判空
     * @param str 原字符串
     */
    public static boolean isEmpty(String str){
        if (str ==null || str.length()==0){
            return true;
        }
        return false;
    }


    public static void main(String[] args){

        System.out.println(formatStr("zhaocaisen",20,"0","left"));
        System.out.println(isEmpty(null));
    }
}
